package wql.aaa.service.impl;

import com.aaa.entity.TbZone;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wql.aaa.dao.ZoneDao;
import wql.aaa.service.ZoneService;
import wql.aaa.vo.SearchFormData;

import java.util.List;

/**
 * @author wql
 * @version 1.0
 * @date 2023/2/27 17:42
 */
@Service
public class ZoneServiceImpl implements ZoneService {

    @Autowired
    private ZoneDao zoneDao;
    @Override
    public Result queryAll(int currentPage, int pageSize, SearchFormData searchFormData) {
        PageHelper.startPage(currentPage,pageSize);
        List<TbZone> tbZones = zoneDao.queryAll(searchFormData);
        PageInfo<TbZone> info = new PageInfo<>(tbZones);
        return new Result(2000,"查询成功",info);
    }


    @Override
    public Result addZone(TbZone tbZone) {
        zoneDao.insert(tbZone);
        return new Result(2000,"添加成功");
    }

    @Override
    public Result deleteByZoneId(String id) {
        QueryWrapper<TbZone> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        zoneDao.delete(wrapper);
        return new Result(2000,"删除成功");
    }

    @Override
    public Result updateZone(TbZone tbZone) {
        zoneDao.updateById(tbZone);
        return new Result(2000,"修改成功");
    }

    @Override
    public Result updateIsDisable(TbZone tbZone) {
        int i = zoneDao.updateById(tbZone);
        System.out.println("i = " + i);
        return new Result(2000,"修改成功");
    }

    @Override
    public Result code(Integer isDisable, String id) {
        Integer code = zoneDao.code(isDisable, id);
        return new Result(2000,"修改成功",code);
    }


}
